<?php
require_once APP . '/application/controllers/FrontAction.php';
require_once APP . '/application/models/ImagesModel.php';
require_once APP . '/application/models/Video.php';

/**
 * 首页
 */
class MediaController extends FrontAction
{
    public function init()
    {
    	$this->view->hmenu = 'media';
    }
    /**
     * 首页
     *
     */
    public function indexAction()
    {
    	
    }
    
    public function listAction()
    {
    	$nowp = intval($this->getParam("nowp", 1));
    	$type = $this->getParam("type", '');
    	
    	if ($type != 'image')
    		$type = "video";
    	
    	if ($type == "image"){
    		$obj_image = new ImagesModel($this->db);
    		$result = $obj_image->fetchAll($nowp, 9);
    		$this->view->typename = _("index_media_im");
    	}else{
    		$obj_video = new Video($this->db);
    		$result = $obj_video->listvideo($nowp, 9);
    		$this->view->typename = _("index_media_video");
    	}
    	$this->view->types = array("video" => array("name" => _("index_media_video"), "id" => "video"),
    	"image" => array("name" => _("index_media_im"), "id" => "image"));
    	
    	$this->view->list = $result['list'];
    	$this->view->page = $result['page'];
    	$this->view->pagenum = Util::pageNumStyle($result['page']);

    	$this->view->type = $type;
    	$this->view->htitle = $this->cfg['lang']['index_media'];
    	
    	$this->render("list");
    }
    
    
    public function detailAction()
    {
    	$id = (int)$this->getParam("id");
    	$vid = (int)$this->getParam("vid");
    	
    	if (!empty($id)){
    		$type = "image";
    		$obj_image = new ImagesModel($this->db);
    		$content = $obj_image->show($id);
    	}else if (!empty($vid)){
    		$type = "video";
    		$obj = new Video($this->db);
    		$content = $obj->show($vid);
    	}else{
    		$this->redirectAction("index", "index");
    	}
    	
    	$this->view->content = $content;
    	$this->view->type = $type;
    	$this->view->types = array("video" => array("name" => _("index_media_video"), "id" => "video"),
    	"image" => array("name" => _("index_media_im"), "id" => "image"));
    	$this->view->onetypename = _("index_media");
    	$this->view->onetypeurl = $this->url($this->baseUrl, "", "list");
    	
    	$this->view->typename = $this->view->types[$type]['name'];
    	$this->render("detail");
    }
    
}
